<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>大类详情</title>
    <!-- 引入 Element UI 的样式 -->
    <link rel="stylesheet" href="../../assets/css/element-ui.css" />
    <link rel="stylesheet" href="../../assets/css/styles.css" />
    <script src="../../assets/js/cdn.js"></script>
    <link rel="stylesheet" href="../../assets/fontawesome-free-6.7.2-web/css/all.min.css" />
  </head>
  <body>
    <div id="app">
      <!-- <div class="header">
        <div class="container header-content">
          <div class="logo">订单管理系统</div>
          <div style="position: absolute; left: 50%;">
            <el-button type="primary" size="large" @click="openMenu('../../index.html')">
              首页
            </el-button>
            <el-dropdown size="large" @command="openMenu">
              <el-button type="primary" size="large">
                业务中心<i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item v-for="item in businessCenters" :command="item.path">{{item.name}}</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
          <div class="user-info" v-if="currentUser.name">
            欢迎，{{ currentUser.name }}
            <el-button type="primary" size="mini" @click="exit(2)">登出</el-button>
          </div>
        </div>
      </div> -->
      <lx-header slot="header" v-on:toggle="isToggle = !isToggle"></lx-header>
      <div class=" main-content">
        <div class="content" style="width: 100%">

          <h1 class="module-title">基本信息</h1>
          <div class="center-grid mb-20">
            <el-descriptions :column="4">
              <el-descriptions-item label="大类名称">
                {{formInfo.configCode}}-{{formInfo.configName}}
              </el-descriptions-item>
            </el-descriptions>
          </div>
          <h1 class="module-title">小类信息</h1>
          <div class="center-grid mb-20">
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="primary" plain size="mini" @click="handleAdd">新增</el-button>
              </el-col>
            </el-row>
            <el-table v-loading="loading" :data="tableData">
              <el-table-column v-for="(item, index) in tableColumnData" :key="index" :label="item.fieldName" min-width="150" :width="item.width">
                <template slot-scope="scope">
                  <template v-if="item.fieldApi === 'configType'"> {{ getConfigTypeOptionsStr(scope.row[item.fieldApi]) }} </template>
                  <template v-else> {{ scope.row[item.fieldApi] }} </template>
                </template>
              </el-table-column>
              <el-table-column label="操作" align="center" :resizable="false" :show-overflow-tooltip="false" width="180" fixed="right">
                <template slot-scope="scope">
                  <el-button size="mini" type="text"  @click="smallConfigDetailView(scope.row)">详情</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
      <el-dialog title="添加小类" :visible.sync="open" :fullscreen="true" width="800px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <el-form-item label="大类名称" prop="bigConfigName">
            <el-input v-model="form.bigConfigName" :disabled="true"></el-input>
          </el-form-item>
          <el-form-item label="小类编码" prop="smallConfigCode">
            <el-input v-model="form.smallConfigCode" placeholder="请输入小类编码"></el-input>
          </el-form-item>
          <el-form-item label="小类名称" prop="smallConfigName">
            <el-input v-model="form.smallConfigName" placeholder="请输入小类名称"></el-input>
          </el-form-item>
          <el-form-item label="选配类型" prop="configType">
            <el-select v-model="form.configType" placeholder="请选择选配类型" clearable>
              <el-option v-for="item in configTypeOptions" :key="item.configTypeCode" :label="item.configTypeName" :value="item.configTypeCode" />
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
    </div>
    <script src="../../assets/js/constant.js"></script>
    <script src="../../assets/js/utils.js"></script>
    <script src="../../assets/js/auth.js"></script>
    <script src="../../assets/js/axios.min.js"></script>
    <!-- 引入 Vue.js -->
    <script src="../../assets/js/vue.js"></script>
    <!-- 引入 Element UI 的 JS 文件 -->
    <script src="../../assets/js/element-ui.js"></script>

    <script type="module">
      import LxHeader from '../../pages/components/LxHeader/index.js'
        Vue.component('lx-header', LxHeader)
      checkAuthentication(2)
      new Vue({
        el: '#app',
        components: {},
        data() {
         return {
            currentUser: JSON.parse(localStorage.getItem('currentUser')) || {},
            userMenuList: JSON.parse(localStorage.getItem('userMenuList')) || [],
            form: {},
            // 表单校验
            rules: {},
            // 是否显示弹出层
            open: false,
            queryParams: {
              pageNo: 1,
              pageSize: 10,
            },
            total: 0,
            tableData: [],
            tableColumnData: [
              {
                fieldName: '小类编号',
                fieldApi: 'smallConfigCode'
              },
              {
                fieldName: '小类名称',
                fieldApi: 'smallConfigName'
              },
              {
                  fieldName: '选配类型',
                  fieldApi: 'configType'
              },
            ],
            // 遮罩层
            loading: true,
            businessCenters: [
                { name: '订单中心', path: '../index.html' },
                { name: '用户中心', path: '#' },
                { name: '产品中心', path: '#' },
                { name: '库存中心', path: '#' },
                { name: '财务中心', path: '#' },
                { name: '数据中心', path: '#' },
                { name: '系统中心', path: '#' },
                { name: '消息中心', path: '#' }
            ],
            optionsObj: [],
            formInfo: {},
            detailDialog: false, // 详情
            carPlatformCode: '',
            root_host: root_host,
            request_host: request_host,
             configTypeOptions: [
                 { configTypeName: '固定', configTypeCode: "0" },
                 { configTypeName: '单选', configTypeCode: "1" },
                 { configTypeName: '多选', configTypeCode: "2" },
             ]
          }
        },
        created() {
            this.init()
        },
        methods: {
          exit,
          getList() {
            this.loading = true
            this.queryParams.bigConfigCode = getUrlParameter('configCode')
            try {
              axios.get(`${this.request_host}/system/smallConfig/allList`,{ params: this.queryParams }).then((response) => {
                if (response.status == 200) {
                  this.tableData = response.data.data
                  this.total = response.data.total
                  this.loading = false
                }
              })
            } catch (error) {
              console.error('请求失败:', error)
            }
          },
          /** 新增按钮操作 */
          handleAdd() {
            this.resetQuery()
            this.open = true
          },
          resetQuery() {
            this.queryParams = {
              pageNo: 1,
              pageSize: 10,
            }
          },
          /** 提交按钮 */
          submitForm() {
            this.$refs["form"].validate(valid => {
              if (valid) {
                  // 新增
                  axios.post(`${this.request_host}/system/smallConfig`, this.form)
                    .then(response => {
                      if (response.data.code == 200){
                        this.$message.success("提交成功")
                        this.cancel();
                        this.getList()
                        const params = `smallConfigCode=`+this.form.smallConfigCode;
                        const url = `small_config_item.html?${params}`;
                        window.open(url, '_blank');
                      }else {
                        this.$message.error(response.data.msg)
                      }
                  })
              }
            })
          },
          // 取消按钮
          cancel() {
            this.open = false
          },
          init() {
            this.configCode = getUrlParameter('configCode')
            this.form.bigConfigCode = this.configCode
            this.getDetails()
            this.getList()
          },
          getDetails() {
            // 这里替换为实际的API调用
            axios.get(`${this.request_host}/system/bigConfig/` + this.configCode)
                .then(response => {
                  this.formInfo = response.data.data
                  this.form.bigConfigName = this.formInfo.configName
                });
          },
          // 获取选配类型描述
          getConfigTypeOptionsStr(value) {
              for (const element of this.configTypeOptions) {
                  if(element.configTypeCode == value){
                      return element.configTypeName
                  }
              }
              return ''
          },
          smallConfigDetailView(row) {
              const smallConfigCode = row.smallConfigCode;
              const params = `smallConfigCode=${encodeURIComponent(smallConfigCode)}`;
              const url = `small_config_item.html?${params}`;
              window.open(url, '_blank');
          },
          openMenu(url) {
            window.open(url)
          },
        }
      })
    </script>
    <style>
      .el-table th.el-table__cell {
        background-color: #f2f2f2; /* 例如，设置为浅灰色 */
      }
    </style>
  </body>
</html>
